package com.example.testwebservcie;

import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.testwebservcie.model.SysUser;

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

import java.net.URL;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private View btnReqWebService;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btnReqWebService=findViewById(R.id.btnReqWebService);
        btnReqWebService.setOnClickListener(getClickEvent());
    }

    private View.OnClickListener getClickEvent(){
        return new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                System.out.println(123);
                if(v==btnReqWebService){
                    btnReqWebService();

                }
            }


        };
    }

    private void btnReqWebService() {
        try{
            JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
            URL url= new URL("http://10.0.0.132:8081/wbs/ws/api?wsdl");
            Client client = dcf.createClient(url);
            Object[] objects = client.invoke("getList");
            String jsonStr = JSONObject.toJSONString(objects[0]);
            JSONArray array = JSONArray.parseArray(jsonStr);
            List<SysUser> sysUserList = JSONObject.parseArray(array.toJSONString(), SysUser.class);
            System.out.println(sysUserList);


        }catch(Exception e){
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

}